<?php
	require('../database/db.php');
	$mysql=new mysql();
	error_reporting(0);

    $cateids = $_REQUEST[zileimuId];
	if($cateids==""){
       $cateids = 0;
	}

	//待过滤的商品
    $filterGoodsidArray = array_filter(explode(',', $_REQUEST[goodsid]));
    $retGoodsidArray = array();
    $query = mysql_query("select  goodsid from goods where  zixilie IN (".$cateids.")");
    while ($row = mysql_fetch_assoc($query)) {
         $retGoodsidArray[] = $row[goodsid]; 
    }
    $result = array_diff($retGoodsidArray,$filterGoodsidArray);
    $resultLength = count($result);
    $newarray = array();
    if(shuffle($result)){// return bool
		for ($i=0; $i<6 && $i<$resultLength; $i++) {
			$newarray[]=$result[$i];
			$filterGoodsidArray[] = $result[$i];
		}
	}
	
	$goodsArray = array();
	if(count(array_filter($newarray))){
        $goodsid = implode(',',$newarray);
        $query = mysql_query("select  goodsid,title,price,yuanjia,images from goods where  goodsid IN (" . $goodsid. ")" . " AND shangjia=1");
	    while ($row = mysql_fetch_assoc($query)) {
	         $goodsArray[] = $row; 
	    }
	}
	
	echo json_encode(array('code'=>200,'msg'=>'查询成功','data'=>$goodsArray,'goodsid'=>implode(',',$filterGoodsidArray)));

/*    $goodsArray = array();
    for($i=0;$i<4;$i++){
        $query = mysql_query("SELECT t1.* FROM `goods`  AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(goodsid) FROM `goods` WHERE zixilie IN (".$cateids."))-(SELECT MIN(goodsid) FROM `goods` WHERE zixilie IN (".$cateids.")))+(SELECT MIN(goodsid) FROM `goods`  WHERE zixilie IN (".$cateids."))) AS goodsid) AS t2 WHERE   t1.goodsid >= t2.goodsid  AND zixilie IN (".$cateids.") ORDER BY t1.goodsid LIMIT 1");
		while ($row = mysql_fetch_assoc($query)) {
			//如果有重复的商品，则再查询多一次
			if(!in_array($row[goodsid], $goodsidArray)){
				$goodsArray[] = $row;
				$goodsidArray[] = $row[goodsid];
			}else{
				$i--;
			}
			
		}
    }
	echo json_encode(array('code'=>200,'msg'=>'ok','data'=>$goodsArray,'goodsid'=>implode(',',$goodsidArray)));*/
/*
require '../../frame/base.php';
if(!isset( $_GET['cateId']) || !is_numeric( $_GET['cateId'])){
	echo json_encode(array('code'=>-200,'msg'=>'获取失败'));
	exit;
}
if(!isset( $_GET['zileimuId'])){
	echo json_encode(array('code'=>-200,'msg'=>'获取失败'));
	exit;
}
$page = 0;
$pagesize = 10;
if(isset($_GET['page'])){
	$page = (int)$_GET['page'];
}
if(isset($_GET['pagesize'])){
	$pagesize = (int)$_GET['pagesize'];
}

$page *= $pagesize;
$cateId = $_GET['cateId'];
$zileimuId = $_GET['zileimuId'];

$result = $Db->table('goods')->field("goodsid,title,price,yuanjia,images")->where(array('zixilie'=>$cateId,'zizixilie'=>array('in',$zileimuId)))->limit($page,$pagesize)->select();

echo json_encode(array('code'=>200,'msg'=>'ok','data'=>$result));

*/
 ?>